﻿using Commons;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RMS.Token;
using RMSIService;
using RMSModel;
using RMSModel.Common;
using RMSModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RMS.Controllers
{
    [ServiceFilter(typeof(TokenFilter))]
    //[ServiceFilter(typeof(ApiAuthFilter))]
    [Route("[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        private readonly IShopService service;

        public ShopController(IShopService service)
        {
            this.service = service;
        }
        [HttpGet]
        public ResultType<List<VMGoods>> GetAllGoods()
        {
            return service.GetAllGoods();
        }
        [HttpGet]
        public ResultType<List<goodstype>> GetAllGoodsType()
        {
            return service.GetAllGoodsType();
        }

        [HttpGet]
        public ResultType<VMGoods> GetGoodsById(int id)
        {
            return service.GetGoodsById(id);
        }
        [HttpGet]
        public ResultType<List<shopuser>> GetAllShopUser()
        {
            return service.GetAllShopUser();
        }
        [HttpGet]
        public ResultType<List<goodstype>> GetAllGoodsTypeWhereLV1()
        {
            return service.GetAllGoodsTypeWhereLV1();
        }

        [HttpPost]
        public ResultType AddGoodsType([FromBody] goodstype g,string userId)
        {
            g.createuser = userId;
            g.createtime = DateTime.Now;
            return service.AddGoodsType(g);
        }
        [HttpPost]
        public ResultType AddGoods([FromBody] VMGoods g, string userId)
        {
            g.createuser = userId;
            g.createtime = DateTime.Now;
            return service.AddGoods(g);
        }
        [HttpPost]
        public ResultType DeleteGoods([FromBody] List<goods> g)
        {
            return service.DeleteGoods(g);
        }
        [HttpPost]
        public ResultType DeleteGoodsType([FromBody] goodstype g)
        {
            return service.DeleteGoodsType(g);
        }


        [HttpGet]
        public ResultType<goodstype> GetGoodsTypeById(int id)
        {
            return service.GetGoodsTypeById(id);
        }
        [HttpPost]
        public ResultType UpdateGoods([FromBody] VMGoods g, string userId)
        {
            g.updatetime = DateTime.Now;
            g.updateuser = userId;
            return service.UpdateGoods(g);
        }
        [HttpPost]
        public ResultType UpdateGoodsType([FromBody] goodstype g, string userId)
        {
            g.updatetime = DateTime.Now;
            g.updateuser = userId;
            return service.UpdateGoodsType(g);
        }
        [HttpPost]
        public ResultType UpdateGoodsStatus(int id,bool status)
        {
            return service.UpdateGoodsStatus(id,status);
        }
        [HttpGet]
        public ResultType<List<order>> GetAllOrder()
        {
            return service.GetAllOrder();
        }
        [HttpPost]
        public ResultType<List<order>> GetOrderByStatus(int status)
        {
            return service.GetOrderByStatus(status);
        }

        [HttpPost]
        public ResultType<List<order>> GetOrderBySn(string no)
        {
            return service.GetOrderBySn(no);
        }
        [HttpGet]
        public ResultType<Dictionary<string,int>> GetOrderGroupCount()
        {
            return service.GetOrderGroupCount();
        }

        [HttpGet]
        public ResultType<List<nideshop_shipping>> GetAllShipping()
        {
            return service.GetAllShipping();
        }
        [HttpPost]
        public  ResultType ConsignmentAsync([FromBody] order g)
        {
            return  service.ConsignmentAsync(g);
        }
    }
}
